/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SpelerToevoegen.java
 *
 * Created on 13-dec-2011, 11:26:36
 */
package view;
import model.Speler;
import javax.swing.*;
/**
 *
 * @author tomkeim
 */
public class SpelerToevoegen extends javax.swing.JFrame {
    private Hoofdscherm hscherm;
    /** Creates new form SpelerToevoegen */
    public SpelerToevoegen() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        naamField = new javax.swing.JTextField();
        adresField = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        postcodeField = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        woonPlaatsField = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        telefoonField = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        emailField = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        spelerToevoegenButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Speler toevoegen");
        setLocationByPlatform(true);

        jLabel1.setText("Naam");

        naamField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                naamFieldActionPerformed(evt);
            }
        });

        jLabel2.setText("Adres");

        jLabel3.setText("Postcode");

        jLabel4.setText("Woonplaats");

        jLabel5.setText("Telefoon");

        jLabel6.setText("Email");

        spelerToevoegenButton.setText("Speler toevoegen");
        spelerToevoegenButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                spelerToevoegenButtonActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(spelerToevoegenButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 467, Short.MAX_VALUE)
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel3)
                            .add(jLabel2)
                            .add(jLabel1)
                            .add(jLabel4)
                            .add(jLabel5)
                            .add(jLabel6))
                        .add(18, 18, 18)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(emailField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 392, Short.MAX_VALUE)
                            .add(telefoonField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 392, Short.MAX_VALUE)
                            .add(woonPlaatsField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 392, Short.MAX_VALUE)
                            .add(naamField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 392, Short.MAX_VALUE)
                            .add(adresField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 392, Short.MAX_VALUE)
                            .add(postcodeField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 392, Short.MAX_VALUE))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(26, 26, 26)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel1)
                    .add(naamField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel2)
                    .add(adresField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel3)
                    .add(postcodeField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel4)
                    .add(woonPlaatsField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel5)
                    .add(telefoonField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel6)
                    .add(emailField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 37, Short.MAX_VALUE)
                .add(spelerToevoegenButton))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void spelerToevoegenButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_spelerToevoegenButtonActionPerformed
        //*SpelerToevoegen eenSpeler = new SpelerToevoegen();
        //jTextField1.getText();
        //eenSpeler.setAdres (jTextField2.getText());
        //eenSpeler.setPostcode (jTextField3.getText());
        //eenSpeler.setWoonplaats (jTextField4.getText());
        //eenSpeler.setTelefoon (jTextField5.getText());
        //eenSpeler.set (jTextField6.getText());
        //eenSpeler.setratingField (ratingField.getText());
        Speler speler = new Speler();
    
      //lees de speler gegevens
      //De println's zijn voor het controleren of het werkt
      String naam = naamField.getText();
      speler.setNaam(naam);
      System.out.println(naam);
      
      String adres = adresField.getText();
      speler.setAdres(adres);
      System.out.println(adres);
      
      String postcode = postcodeField.getText();
      speler.setPostcode(postcode);
      System.out.println(postcode);
      
      String woonplaats = woonPlaatsField.getText();
      speler.setWoonplaats (woonplaats);
      System.out.println(woonplaats);
      
      String telefoon = telefoonField.getText();
      speler.setTelefoonNummer(telefoon);   // Nick : De reden is dat wij telefoonnr als Int opslaan, Dus de 0 wordt genegeerd omdat hij vooraan staat.
      System.out.println(telefoon);         // 063904 wordt 63904 bijv
      // Mogelijke oplossing, Int ophalen, naar String veranderen en als String in DB opslaan.
      String email = emailField.getText();
      speler.setEmail(email);
      System.out.println(email);
      
      int rating = 100;
      speler.setRating(rating);
      System.out.println(rating);
     
     String empty = "";
     if (!naam.equals(empty) && !adres.equals(empty) && !postcode.equals(empty) && !woonplaats.equals(empty) && !telefoon.equals(empty) && !email.equals(empty)) {
          
     if (Speler.getSpelerEmail(email) == false) {
      
     if (speler.insert() == true) {
         JOptionPane.showMessageDialog(null, "De Speler is succesvol toegevoegd.");
     }
     }
     else
     {
         JOptionPane.showMessageDialog(null, "De Speler bestaat al!");
     }
     }
     else{
         JOptionPane.showMessageDialog(null, "U mag geen velden leeg laten");
     }
    }//GEN-LAST:event_spelerToevoegenButtonActionPerformed

    private void naamFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_naamFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_naamFieldActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(SpelerToevoegen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(SpelerToevoegen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(SpelerToevoegen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(SpelerToevoegen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new SpelerToevoegen().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField adresField;
    private javax.swing.JTextField emailField;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JTextField naamField;
    private javax.swing.JTextField postcodeField;
    private javax.swing.JButton spelerToevoegenButton;
    private javax.swing.JTextField telefoonField;
    private javax.swing.JTextField woonPlaatsField;
    // End of variables declaration//GEN-END:variables
}
